<html>
<head>
<title>DIGI-Infomat</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<link href="style.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        .style1
        { width: 20%;}
    </style>
    
<script type="text/javascript">
function lastname(upload_name, suffix_check){
	var filepath = document.getElementById(upload_name).value; 
	if(filepath=="") {
		alert ('Please Select File');
		return false;
	}
	if (upload_name == 'browse_image') {
		if (0==document.getElementById('div_html_radio_group').hasChildNodes())
		{
			alert ('There is no HTML file in the list, please upload first');
			return false;
		}
	}
	//div -- getElementById(DivId).hasChildNodes()
	var re = /(\\+)/g; 
	var filename=filepath.replace(re,"#");
	var one=filename.split("#");
	var two=one[one.length-1];
	var three=two.split(".");
	var last=three[three.length-1];
	//var tp ="jpg,gif,bmp,JPG,GIF,BMP";
	var rs=suffix_check.indexOf(last);
	//alert (rs);
	if(rs>=0){
 		return true;
 	}else{
		var err = "please upload "+suffix_check + " file";
 		alert(err);
 		return false;
  	}
}
</script>
</head>

<?php
/***************************** PHP **********************************/
	include "uploader.php";
	include  "xplaylist.php";
	include "xutility.php";
	
	$xUploader = new Uploader ();
	$xlist = new XPlayList ();
	$xUtility = new XUtility();

    if (!empty($_POST)) {	
		//echo "<pre>";  /*{{{*/
        //print_r($_POST);
		//echo "</pre>";  /*}}}*/
		if (isset($_POST['upload_html']))
		{
       		$upload_html = $_POST['upload_html'];
			if ('upload html' == $upload_html) {
				$xUploader->upload($_FILES['browse_html'], 'html_path');
				$xUtility->createHtmlImageDir($_FILES['browse_html']['name']);
			}
		} //end-of-upload
		
		if (isset($_POST['upload_movie']))
		{
			$upload_movie = $_POST['upload_movie'];
			if ('upload movie' == $upload_movie) {
				$xUploader->upload($_FILES['browse_movie'],'movie_path');
			}
		}
		
		if (isset($_POST['html_radio'])) /*{{{*/ //handle with html radio
		{
			$html_file = $_POST['html_radio'];
			//echo "<pre>"; /*{{{*/
        	//print_r($_POST);
        	//echo $html_file;
			//echo "</pre>"; /*}}}*/
			if (isset($_POST['delete_html'])) 
			{
				if ('delete' == $_POST['delete_html']){
					$xUtility->deleteHtmlFileWithImages($html_file);
				}
			}
			if (isset($_POST['upload_image'])) {
				//echo "<pre>";
				//print_r ($_FILES['browse_image']);
				//print_r ($_POST['upload_image']);
				//echo "<pre>";
				if ('upload image' == $_POST['upload_image']) {
					$xUploader->setSelectedHtml($html_file);
					$xUploader->upload($_FILES['browse_image'], 'image_path');
				}
			}
		}  //end-of-process html /*}}}*/

		/* -----------  Movie List Form --------------------*/
		if (isset($_POST['movie_radio'])) /*{{{*/ 
		{
			$movie_file = $_POST['movie_radio'];
			//echo "<pre>"; /*{{{*/
        	//print_r($_POST);
        	//echo $movie_file;
			//echo "</pre>"; /*}}}*/
			if (isset($_POST['delete_movie'])) 
			{
				if ('delete' == $_POST['delete_movie']){
					$xUtility->deleteMovie($movie_file);
				}
			}
		}  //end-of-process html /*}}}*/
    } //end-of-POST
/* **************************** PHP **********************************/
?>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="text-align:center">
<table width="100%"> 
<tr>
   <td align="center">
        <table width="780px" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <table border="0" bgcolor="#FFFFFF" width="100%">
						<tr>
                            <td rowspan="2" width="20%"><img src="images/logo.png" alt="logo"></td>
						</tr>
						       
						<tr valign="bottom"  align="center">
                            <td><a href="home.php"><img style="border-width:0px;" src="images/btn_home.png"  alt="HOME"></a></td>
                            <td><a href="network.php"><img style="border-width:0px;" src="images/btn_network.png" alt="Network Setting"></a></td>
                            <td><a href="update.php"><img style="border-width:0px;" src="images/btn_update.png" alt="Update"></a></td>
                            <td><a href="setting.php"><img style="border-width:0px;" src="images/btn_setting.png" alt="setting"></a></td>
                            <td><a href="filemanage.php"><img style="border-width:0px;" src="images/btn_filemanage.png" alt="File Manage"></a></td>
                        </tr>
                    </table>
               	</td>
            </tr> 
			<tr>
                <td colspan="2">
					<table border="0" cellspacing="0" cellpadding="0"></table>
				</td>
			</tr>
            <tr>
            	<td colspan="2" valign="middle" bgcolor="#FFFFFF">
				<form name="updateForm" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                    <table border="0" cellspacing="0" cellpadding="0"  width="780px" class="form_table">
                    	<tr> 
                        <td width="3%" >&nbsp;</td>
						<td valign="middle" class="name" style="width:380px;"
><strong class="green-text">Upload Files</strong></td>
                          <td  width="450px" >&nbsp;</td>
                         
                      	</tr>
						<tr>
                           <td></td>
                           <td valign="middle" class="style1" style="width:140px;"><strong>Upload HTML </strong></td>
                           <td align="left" ><input type="file" name="browse_html" value="Choose HTML " id="browse_html" />
                             <span style="width:140px;">
                             <input type="submit" name="upload_html" value="upload html" id="uploadHtml" onClick="return lastname('browse_html','.html,.htm')" >
                             </span></td>
                        </tr>
				    <tr>
						  <td></td>
						  <td valign="middle"style="width:140px;"><strong>Upload Movies</strong> <span class="orange-text-regular"><font size="-1"> <a href="images/supportformat.png" class="orange-text-underline">support format</a></font></span></td>
						  <td align="left" ><input type="file" name="browse_movie" value="Choose Movie " id="browse_movie"  />
						    <span style="width:140px;">
						    <input type="submit" name="upload_movie" value="upload movie" id="upload3" onClick="return lastname('browse_movie','avi,flv,wmv,jpg,jpeg,png,bmp,gif')" >
					      </span></td>
					  </tr>
					</table>
				</form>
                  
                  <table border="0" cellspacing="0" cellpadding="0"  width="780px">
                    <tr>
                    	<td valign="middle" style="width:3%;">&nbsp;</td>
                    	<td valign="top" align="left" style="width:380px"> 
                    		<form name="htmlForm" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>">
							<?php
                      			$xlist->showHtmlListTable();
					   		?>
                            <br>
                         </form>
                       </td>
                       <td valign="top" align="left" style="width:380px">
                   <form name="MovieForm" method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>">
					<?php
						$xlist->showMovieListTable();
					 ?>
                            <br> 
                         </form>
                       </td>
                       </tr>
                    </table>
				</td>
            </tr>
	    <tr>
		<td colspan="2" align="center" class="white-text">
		    <table width="100%" border="0" cellspacing="0" cellpadding="10">
			<tr>
			<td align="center" class="white-text">Copyright &copy;  Teraoka Weigh System. All Rights Reserved.</td>
			</tr>
		    </table>
		</td>
	    </tr>
	</table>
   </td>
</tr>
</table>

</body>
</html>
